<template>
    <div>
        <!--        <el-card ref="card"  class="box-card">-->
        <!--            <div class="tree-div" style="height: 35px">-->
        <!--                <el-checkbox v-model="deptExpand"-->
        <!--                             @change="handleCheckedTreeExpand($event, 'tree')">-->
        <!--                    展开/折叠-->
        <!--                </el-checkbox>-->
        <!--            </div>-->
        <div class="group-menu-tree" style="height: 900px">
            <el-empty v-if="!data" description="暂无科室数据"></el-empty>
            <template v-else>
                <el-input
                    v-model="filterText"
                    placeholder="输入关键字进行过滤">
                </el-input>

                <el-tree
                    ref="tree"
                    :data="data"
                    :default-checked-keys="defaultCheckedKeys"
                    :expand-on-click-node="false"
                    :filter-node-method="filterNode"
                    :highlight-current=true
                    :props="defaultProps"
                    :show-checkbox="showCheckbox"
                    class="filter-tree"
                    default-expand-all
                    node-key="id"
                    @node-click="nodeClick">
                </el-tree>
            </template>
        </div>
        <!--        </el-card>-->
    </div>
</template>

<script>

import store from "@/store";

export default {
    name: "NavDeptTree",
    data () {
        return {
            filterText: '',
            data: [],
            defaultProps: {
                children: 'children',
                label: 'deptName'
            },
            deptExpand: true,
        }
    },
    props: {
        showCheckbox: {
            type: Boolean,
            default: false
        },
        defaultCheckedKeys: {
            type: [Array],
            default: () => []
        }
    },
    watch: {
        filterText (val) {
            this.$refs.tree.filter(val)
        },
        defaultCheckedKeys (val) {
            this.judgmentAllSelection(val)
        }
    },
    mounted () {
    },
    methods: {
        /** 获取用户权限科室 */
        getPersonnelAuthorityDept () {
            this.data = this.$store.getters.deptList
        },
        /** 搜索 */
        filterNode (value, data) {
            if (!value) return true
            return data.label.indexOf(value) !== -1
        },
        /** 树节点点击事件 */
        nodeClick (a, b, c) {
            this.$emit('treeClick', a)
        },
        // 树权限（展开/折叠）
        handleCheckedTreeExpand (value, type) {
            let treeList = this.data;
            for (let i = 0; i < treeList.length; i++) {
                this.$refs.tree.store.nodesMap[treeList[i].id].expanded = value;
            }
        },
    },
}
</script>

<style scoped>
.box-card {
    overflow-y: auto
}
</style>
